import time
import logging

# logging.basicConfig(level=logging.DEBUG,
#                     format='%(asctime)s %(filename)s %(funcName)s %(lineno)d %(message)s')
# logger = logging.getLogger(__name__)
#
# logger.debug('Watch Out!')

# 日志记录器
logger = logging.getLogger()

# 设置日志格式
fmt = logging.Formatter('%(levelname)-8s%(asctime)s:%(filename)s:%(lineno)d %(message)s')

# 输出到控制台
console = logging.StreamHandler()
console.setFormatter(fmt)
logger.addHandler(console)

# 输出到文件
file = logging.FileHandler(f'{time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())}.log')
file.setFormatter(fmt)
logger.addHandler(file)

# 设置日志级别
logger.setLevel(logging.DEBUG)

logger.debug(f'Watch Out!, {time.time()}')
logger.info('Watch Out!')
logger.warning('Watch Out!')
logger.error('Watch Out!')
logger.info(f"{type(logger)}")

